/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PatientAllergiesPanel.java
 *
 * Created on Aug 14, 2011, 7:50:14 PM
 */
package panels;

import conn.EMIS4Connection;
import dao.AllergiesDao;
import dao.AllergiesSpecificDao;
import java.sql.SQLException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import obj.Allergies;
import obj.AllergiesSpecific;
import obj.Person;
import util.PersonRequested;

/**
 *
 * @author NATHAN
 */
public class PatientAllergiesPanel extends javax.swing.JPanel {

  private EMIS4Connection conn = EMIS4Connection.getInstance();
  private PersonRequested pr = PersonRequested.getInstance();
  private AllergiesDao allergiesDAO;
  private List<Allergies> allergiesList;
  private AllergiesSpecificDao allergiesSpecificDAO;
  private List<AllergiesSpecific> allergiesSpecificList;
  private Person patient;

  /** Creates new form PatientAllergiesPanel */
  public PatientAllergiesPanel() {

    allergiesDAO = new AllergiesDao();
    allergiesSpecificDAO = new AllergiesSpecificDao();

    initComponents();

    fillInformation();
  }

  private void fillInformation() {
    try {
      patient = pr.getPerson();

      conn.connect();
      allergiesList = allergiesDAO.searchMatching(conn.getConnection(), new Allergies(patient));
      allergiesSpecificList = allergiesSpecificDAO.loadAll(conn.getConnection());

      // fill combo boxes
      for (AllergiesSpecific item : allergiesSpecificList) {
        allergy1ComboBox.addItem(item.getAllergyName());
        allergy2ComboBox.addItem(item.getAllergyName());
        allergy3ComboBox.addItem(item.getAllergyName());
        allergy4ComboBox.addItem(item.getAllergyName());
        allergy5ComboBox.addItem(item.getAllergyName());
        allergy6ComboBox.addItem(item.getAllergyName());
        allergy7ComboBox.addItem(item.getAllergyName());
        allergy8ComboBox.addItem(item.getAllergyName());
      }

      // set allergies
      switch (allergiesList.size()) {
        case 8:
          allergy8ComboBox.setSelectedIndex(allergiesList.get(7).getAllergyID());
        case 7:
          allergy7ComboBox.setSelectedIndex(allergiesList.get(6).getAllergyID());
        case 6:
          allergy6ComboBox.setSelectedIndex(allergiesList.get(5).getAllergyID());
        case 5:
          allergy5ComboBox.setSelectedIndex(allergiesList.get(4).getAllergyID());
        case 4:
          allergy4ComboBox.setSelectedIndex(allergiesList.get(3).getAllergyID());
        case 3:
          allergy3ComboBox.setSelectedIndex(allergiesList.get(2).getAllergyID());
        case 2:
          allergy2ComboBox.setSelectedIndex(allergiesList.get(1).getAllergyID());
        case 1:
          allergy1ComboBox.setSelectedIndex(allergiesList.get(0).getAllergyID());
      }

    } catch (SQLException ex) {
      Logger.getLogger(PatientAllergiesPanel.class.getName()).log(Level.SEVERE, null, ex);
    }

  }

  /** This method is called from within the constructor to
   * initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is
   * always regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {
    java.awt.GridBagConstraints gridBagConstraints;

    jLabel1 = new javax.swing.JLabel();
    jLabel2 = new javax.swing.JLabel();
    allergy1ComboBox = new javax.swing.JComboBox();
    allergy2ComboBox = new javax.swing.JComboBox();
    allergy3ComboBox = new javax.swing.JComboBox();
    allergy4ComboBox = new javax.swing.JComboBox();
    allergy5ComboBox = new javax.swing.JComboBox();
    allergy6ComboBox = new javax.swing.JComboBox();
    allergy7ComboBox = new javax.swing.JComboBox();
    allergy8ComboBox = new javax.swing.JComboBox();
    submitButton = new javax.swing.JButton();

    setBackground(new java.awt.Color(220, 220, 210));
    setLayout(new java.awt.GridBagLayout());

    jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
    jLabel1.setText("Allergies");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
    gridBagConstraints.insets = new java.awt.Insets(20, 15, 10, 15);
    add(jLabel1, gridBagConstraints);

    jLabel2.setText("Patient Allergies:");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 1;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
    gridBagConstraints.insets = new java.awt.Insets(6, 25, 0, 0);
    add(jLabel2, gridBagConstraints);

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 2;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
    gridBagConstraints.insets = new java.awt.Insets(7, 35, 0, 0);
    add(allergy1ComboBox, gridBagConstraints);

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 3;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
    gridBagConstraints.insets = new java.awt.Insets(7, 35, 0, 0);
    add(allergy2ComboBox, gridBagConstraints);

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 4;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
    gridBagConstraints.insets = new java.awt.Insets(7, 35, 0, 0);
    add(allergy3ComboBox, gridBagConstraints);

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 5;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
    gridBagConstraints.insets = new java.awt.Insets(7, 35, 0, 0);
    add(allergy4ComboBox, gridBagConstraints);

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 6;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
    gridBagConstraints.insets = new java.awt.Insets(7, 35, 0, 0);
    add(allergy5ComboBox, gridBagConstraints);

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 7;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
    gridBagConstraints.insets = new java.awt.Insets(7, 35, 0, 0);
    add(allergy6ComboBox, gridBagConstraints);

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 8;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
    gridBagConstraints.insets = new java.awt.Insets(7, 35, 0, 0);
    add(allergy7ComboBox, gridBagConstraints);

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 9;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
    gridBagConstraints.insets = new java.awt.Insets(7, 35, 0, 0);
    add(allergy8ComboBox, gridBagConstraints);

    submitButton.setText("Submit");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 10;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
    gridBagConstraints.weightx = 0.1;
    gridBagConstraints.weighty = 0.1;
    gridBagConstraints.insets = new java.awt.Insets(15, 65, 15, 15);
    add(submitButton, gridBagConstraints);
  }// </editor-fold>//GEN-END:initComponents
  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JComboBox allergy1ComboBox;
  private javax.swing.JComboBox allergy2ComboBox;
  private javax.swing.JComboBox allergy3ComboBox;
  private javax.swing.JComboBox allergy4ComboBox;
  private javax.swing.JComboBox allergy5ComboBox;
  private javax.swing.JComboBox allergy6ComboBox;
  private javax.swing.JComboBox allergy7ComboBox;
  private javax.swing.JComboBox allergy8ComboBox;
  private javax.swing.JLabel jLabel1;
  private javax.swing.JLabel jLabel2;
  private javax.swing.JButton submitButton;
  // End of variables declaration//GEN-END:variables
}
